package com.itheima.health.service.impl;

import com.itheima.health.dao.ReserationDao;
import com.itheima.health.pojo.CheckGroup;
import com.itheima.health.pojo.CheckItem;
import com.itheima.health.pojo.Setmeal;
import com.itheima.health.service.ReservationService;
import org.apache.ibatis.annotations.Select;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ReservationServiceImpl implements ReservationService {
    @Autowired
    private ReserationDao reserationDao;
    /*
    * 查询套餐表以及关联表
    * */
    @Override
    public List<Setmeal> getSetmealAll() {
        //先查询所有套餐数据
       List<Setmeal> setmeallist = reserationDao.getSetmealAll();
       //然后遍历这个集合根据id查询分组表
        for (Setmeal setmeal1 : setmeallist) {
            //根据id查询分组表
           List<CheckGroup> checkGroups = reserationDao.getByidGoup(setmeal1);
           setmeal1.setCheckGroups(checkGroups);
        }

        return setmeallist;
    }
/*
* 根据id查询分组详情
* */
    @Override
    public Setmeal fianByid(Integer id) {
        //根据套餐id查询套餐分组表
       Setmeal setmeal = reserationDao.fianBid(id);
       //根据套餐表id查查询分组表
      List<CheckGroup> checkGroupList=  reserationDao.getByidGoup(setmeal);
      setmeal.setCheckGroups(checkGroupList);
      //遍历分组id 根据分组id查询项目
        for (CheckGroup checkGroup : checkGroupList) {
          List<CheckItem> checkItemList=  reserationDao.getGoupid(checkGroup);
          checkGroup.setCheckItems(checkItemList);
        }
        return setmeal;
    }
}
